package com.jk.libsm.controller;

import com.alibaba.fastjson.JSONObject;
import com.jk.libsm.service.Bookservice;
import com.jk.libsm.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class BookController {

    @Autowired
    Bookservice bookservice;

    //按条件查询书
    @PostMapping("/book/findbooks")
    public Result findbooks(@RequestBody JSONObject jsonObject) {
        String token = jsonObject.get("token").toString();
        int type = Integer.parseInt(jsonObject.get("type").toString());
        String info = jsonObject.get("info").toString();
        return bookservice.bookFindbooks(token,type,info);
    }

    //获取被借次数最多的十本书
    @PostMapping("/find_top_books")
    public Result findTopBooks(@RequestBody JSONObject jsonObject) {
        String token = jsonObject.get("token").toString();
        return bookservice.bookFindTopBooks(token);
    }

    //查询到期但是未归还的图书
    @PostMapping("/find_over_books")
    public Result findOverBooks(@RequestBody JSONObject jsonObject){
        String token = jsonObject.get("token").toString();
        return  bookservice.findOverBooks(token);
    }

    //查询所有借出去的图书
    @PostMapping("/find_borrow_books")
    public Result findBorrowBooks(@RequestBody JSONObject jsonObject){
        String token = jsonObject.get("token").toString();
        return bookservice.findBorrowBooks();
    }

}


